pp108 : Validations on Task Actions

Validations on Task Actions

This topic describes various custom validations that can be done on the task actions.

When you perform an action on a human task of a BPM, Case Model, or any other source, validations can be performed before and after the specific action is done. For instance, you may want to restrict a user from claiming more than one task at a time. To do that, you can provide your logic in the OnBeforeClaim hook, which is called when a task or the Case activity is claimed and verifies if the user has already claimed it. If it is found to be claimed already, the user is restricted from claiming this task or the Case activity.
To do this, you must write a Web library as described in the Sample Validations Library. Refer to the table below for a complete list of available validations and refer to Creating a Web Library Definition for creating a Web library in CWS.

After creating the Web library, you must call the action validations defined in this Web library as follows:

  1. Update the entry in the XML Store Key /Cordys/notification/task/taskoperationlibraries.xml. If this entry is not present, you can create an XML Store definition from CWS.
  2. Add the custom validations library for your model as provided in the sample code snippet below:
    <TaskOperationsLibrary>
        <!--You can provide as many model elements as required.-->
        <model fqn="CasesAndBPMs/Sales">
            <libraryurl>cpc.nsinbox.utils.SalesTasksEventHandler</libraryurl>
        </model>
    </TaskOperationsLibrary>
    

    Note: You can add multiple model nodes in the same XML Store definition entry and specify validation libraries for multiple models.

  3. Provide the model names and the relative URLs as many as required in the format provided in the sample code snippet above.
Element Description Accepted Input Values
model fqn Fully Qualified Name of the Case Model or Business Process Model For example: sample/case/casemodel1
libraryurl Relative URL of the library that contains the validations

For example: cpc.nsinbox.utils.SalesTasksEventHandler

  • You must provide the logic that validates various actions in the relevant code blocks.
  • The SalesTasksEventHandler.htm file must be created in the location mentioned in the libraryurl; for instance, /cordys/cpc/nsinbox/utils folder as provided in the code snippet above.
    To view the pre-defined structure of the task validation library, refer to Pre-defined Structure of the Task Validation Library.
    While performing the required operations on the tasks, the relevant prototype methods are invoked.
    Note: It is suggested that you remove the prototype methods, which are not required from the file. This reduces the file size, thereby reducing the loading time.

Validations on task action. The following table describes various validations that can be performed on the task actions:

Action Validations Description
ASSIGN OnBeforeAssign Fired before a task is assigned
OnAfterAssign Fired after a task is assigned
CLAIM OnBeforeClaim

Fired before a task is claimed

Note::

  • When the Automatically Claim / Revoke Claim in Inbox check box is selected while configuring the Notification service container and you perform some action such as starting the task, the validation is done in the following order:
    • Claim
    • OnBeforeClaim
    • OnAfterClaim
    • OnBefore<action> - for example: OnBeforeStart
    • OnAfter<action> - for example: OnAfterStart
  • If the Automatically Claim / Revoke Claim in Inbox check box is selected, and you open an unclaimed task, view and close it without performing any actions, no validation is done on the task or Case activity.
  • If the Automatically Claim is not enabled and you claim the task and close it without performing any operation, the OnBeforeClaim and OnAfterClaim events are fired.
OnAfterClaim Fired after a task is claimed
REVOKECLAIM OnBeforeRevokeClaim Fired before a claimed task is revoked
OnAfterRevokeClaim Fired after a claimed task is revoked
COMPLETE OnBeforeCommit Fired before a task is completed
OnAfterCommit

Fired after a task is completed

If you want to override the action to open the next available task from the related activities in the Case instance, the Workflow.taskView.openTask() API can be used. Also, the dataObject.dontOpenNextActivity flag must be set to true.

 //In the prototype OnAfterComplete, add the following logic to override the default behavior.
ActivityHookLib.prototype.OnAfterCommit = function(dataObject, callBackFunction)
{
  Workflow.taskView.openTask(sTaskId);
  dataObject.dontOpenNextActivity = true;
  callBackFunction(dataObject);
}

If you do not want to open any activity but open Case instance view, set the dataObject.openCaseInstanceView flag to true.

//In the prototype OnAfterComplete add the following code to open Case instance view.
ActivityHookLib.prototype.OnAfterCommit = function(dataObject, callBackFunction)
{
  dataObject.openCaseInstanceView = true;
  callBackFunction(dataObject);
}
DELEGATE OnBeforeDelegate Fired before a task is delegated
OnAfterDelegate Fired after a task is delegated
FORWARD OnBeforeForward Fired before a task is forwarded
OnAfterForward Fired after a task is forwarded
PAUSE OnBeforePause Fired before a task is paused
OnAfterPause Fired after a task is paused
RESUME OnBeforeResume Fired before a task is resumed
OnAfterResume Fired after a task is resumed
START OnBeforeStart Fired before a task is started
OnAfterStart Fired after a task is started
STOP OnBeforeStop Fired before a task is stopped
OnAfterStop Fired after a task is stopped
SUSPEND OnBeforeSuspend Fired before a task is suspended
OnAfterSuspend Fired after a task is suspended
TRANSFER OnBeforeTransfer Fired before a task is transferred
OnAfterTransfer Fired after a task is transferred
SKIP OnBeforeSkip Fired before a task is skipped
OnAfterSkip

Fired after a task is skipped

If you want to override the action to open the next available task from related activities in the Case instance, the Workflow.taskView.openTask() API can be used. Also, the dataObject.dontOpenNextActivity flag must be set to true.

 //In the prototype OnAfterSkip add the following logic to override the default behavior.
ActivityHookLib.prototype.OnAfterSkip = function(dataObject, callBackFunction)
{
  Workflow.taskView.openTask(sTaskId);
  dataObject.dontOpenNextActivity = true;
  callBackFunction(dataObject);
}

If you want to open the Case instance view without opening any activity, set the dataObject.openCaseInstanceView flag to true.

//In the prototype OnAfterSkip, add the following code to open the Case instance view.
ActivityHookLib.prototype.OnAfterSkip = function(dataObject, callBackFunction)
{
  dataObject.openCaseInstanceView = true;
  callBackFunction(dataObject);
}
ADD MEMO OnBeforeMemo Fired before a memo is added to the task
OnAfterMemo Fired after a memo is added to the task
ADD ATTACHMENT OnBeforeAttachment Fired before a file is attached to the task
OnAfterAttachment Fired after a file is attached to the task
UPDATE ATTACHMENT OnBeforeUpdateAttachment Fired before an attachment to a Case activity is updated. Applicable for Case activities only.
OnAfterUpdateAttachment Fired after an attachment to a Case activity is updated. Applicable for Case activities only.
DELETE ATTACHMENT OnBeforeDeleteAttachment Fired before an attachment to a Case activity is deleted. Applicable for Case activities only.
OnAfterDeleteAttachment Fired after an attachment to a Case activity is deleted. Applicable for Case activities only.

PLAN INTERMEDIATE FOLLOWUPS

OnBeforePlanInterMediateFollowups

Fired before the intermediate followups are planned from Case activity. Applicable for Case activities only.
OnAfterPlanInterMediateFollowups Fired after the intermediate followups are planned from Case activity. Applicable for Case activities only.

PLAN FREE FOLLOWUPS

OnBeforePlanFreeFollowUps Fired before free followups are planned from the Case activity or Case instance view. Applicable for Case activities only.
OnAfterPlanFreeFollowUps Fired after free followups are planned from the Case activity or Case instance view. Applicable for Case activities only.

OPEN

OnAfterOpen

Properties :

  • isCaseOverviewRefreshRequired 

Fired after a Case activity is opened.

By default, the Case Overview tab refreshes while switching between the activities. If you do not want this behavior, set the dataObject.isCaseOverviewRefreshRequired flag to false.

//In the prototype OnAfterOpen add the following code, so that the data or UI in the Case Overview tab will not be refreshed while switching between the activities of the same Case model.
ActivityHookLib.prototype.OnAfterOpen = function(dataObject, callBackFunction)
{
  dataObject.isCaseOverviewRefreshRequired = false;
  callBackFunction(dataObject);
}
CLOSE OnBeforeClose Fired before a Case activity is closed

Note: All the validations provided in the table above require dataObject and callback function as parameters.

  • dataObject- The dataObject parameter has CaseInstanceId, TaskId, ReturnValue, and Workflow object as task data. You can retrieve the task data as shown below:
    • CaseInstanceID or ProcessInstanceID:
      	for(var ctr = 0; ctr < SelectedOptions.length; ctr++)
      	{
      		alert(dataObject.SelectedOptions[ctr].SourceInstanceId);
      	}
      
    • TaskID:
      	for(var ctr = 0; ctr < SelectedOptions.length; ctr++)
      	{
      		alert(dataObject.SelectedOptions[ctr].TaskId);
      	}
      
    • ReturnValue:
      	for(var ctr = 0; ctr < SelectedOptions.length; ctr++)
      	{
      		alert(dataObject.SelectedOptions[ctr].ReturnValue);
      	}
      
    • Workflow - dataObject.Workflow. Refer to Workflow for more information.
  • callback function- This function is used to give the control back to the framework. Ensure that you do not make any changes to this function, and your validation logic ends with it.